import pymysql
from src.Utils.index import colored_text

"""
mysql 数据库配置信息
"""
class MYSQL_CONFIG:
    HOST =  '127.0.0.1'
    PORT= 3306
    USERNAME= 'root'
    PASSWORD= '123456'
    DATABASE= 'ych'

def connect(host: str,port: int,username: str,password: str,database: str):
    print(colored_text("---------正在连接数据库---------","yellow"))
    db = None
    try:
        db = pymysql.connect(host=host,port=port,user=username,
                             password=password,database=database,cursorclass=pymysql.cursors.DictCursor)
        print(colored_text("---------数据库连接成功---------","green"))
    except:
        print(colored_text("---------数据库连接失败---------","red"))
    return db